﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.SessionState;
using System.Configuration;

namespace KPIS.GERP.GFMS.APP.App_UI.Commons
{
    namespace WebDb
    {
        //Db control dataset
        public class Db : IRequiresSessionState
        {
            //connection Database
            public static SqlConnection getConnect()
            {
                string dbConn = ConfigurationManager.AppSettings["ConnectionString"].ToString();
                SqlConnection _con = new SqlConnection(dbConn);
                return _con;
            }

            //Query in Dataset to function
            public static DataSet exe(string _query, string _name = "name auto")
            {
                SqlDataAdapter _adp = new SqlDataAdapter(_query, getConnect());//connect
                DataSet _ds = new DataSet();
                try
                {
                    if (_name == "name auto")
                    {
                        _adp.Fill(_ds);
                    }
                    else
                    {
                        _adp.Fill(_ds, _name);
                    }
                    _adp.Dispose();
                }
                catch (Exception e)
                {
                    throw new Exception("Error in connecting DataSet" + e.Message);
                    //_adp.Dispose();
                }
                return _ds;
            }
        }
    }
}